package org.apache.rocketmq.simples.springboot;


import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;
import java.util.List;

@SpringBootApplication
public class PullConsumerApplication implements CommandLineRunner {
    @Resource
    private RocketMQTemplate rocketMQTemplate;
    
    @Value("${rocketmq.pull-consumer.topic}")
    private String topic;

    public static void main(String[] args) {
        SpringApplication.run(PullConsumerApplication.class, args);
    }

    @Override
    public void run(String... args) {
        for (int i = 0; i < 100; i++) {
            // 使用正确的方法签名并设置超时时间，避免长时间阻塞
            List<String> messages = rocketMQTemplate.receive(String.class, 1000);
            System.out.println(messages);
        }
    }
}